package com.whs.demo.application;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.jglfw.JglfwApplication;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.whs.demo.Demo;
import com.whs.demo.progress.CircularProgress;
import com.whs.demo.ui.Slider;

public class ProgressTest extends Demo {

	Stage stage;
	CircularProgress circularProgress;
	CircularProgress sectorActor2;
	Texture level1;
	Texture level2;
	Texture level3;
	Image image;
	private float time;
    private float testP;
    private Slider slider;
    private float expectedProgress;

	@Override
	public void create() {
		level1 = new Texture("data/pic/level1.png");
		level2 = new Texture("data/pic/level2.png");
		level3 = new Texture("data/pic/level3.png");
		circularProgress = new CircularProgress(new TextureRegion(level1));
		circularProgress.setPercent(1F);
		circularProgress.setPosition((WIDTH - level1.getWidth()) / 2,
				(HEIGHT - level1.getHeight()) / 2);
//		sectorActor2 = new CircularProgress(new TextureRegion(level2));
		
		image = new Image(level3);
		image.setPosition((WIDTH - level3.getWidth()) / 2,
				(HEIGHT - level3.getHeight()) / 2);
		stage = new Stage();
//		stage.addActor(image);
        stage.addActor(circularProgress);
        slider = new Slider();
        expectedProgress = 0;
	}
	
    // 在该处演示百分比的变化
    public float getProgress() {
        float f = (int) testP / 20F;
        if (f > 1) {
            testP = 0;
        }
        return f;

    }
	

	@Override
	public void render() {
		super.render();
		stage.act();
		stage.draw();
		time +=  Gdx.graphics.getDeltaTime() / 10;
		if (time > 1) {
			time = 0;
		}
		act(Gdx.graphics.getDeltaTime());
//		sectorActor2.setPercent(0.5F);
		circularProgress.setPercent(slider.getPercent());
//		sectorActor2.setPercent(time);
	}

	@Override
	public void dispose() {
		stage.dispose();

	}
	
	public void act(float delta){
	    
        testP += delta;
        float progress = getProgress();
        /**
         * 更新进度
         */
        if (expectedProgress != progress) {
            slider.setup(expectedProgress, progress);
            expectedProgress = progress;
        }
        slider.update(delta);
	}

	public static void main(String[] args) {
		new JglfwApplication(new ProgressTest(),
				ProgressTest.class.getSimpleName(), Demo.WIDTH, Demo.HEIGHT);
	}

}
